// src/api/userApi.ts
import { http } from './request'

type User = {
    id: number
    username: string
    password?: string
}

export const userApi = {
    // 获取用户列表
    fetchUsers: () => http.get<User[]>('/users'),

    // 创建用户
    createUser: (user: Pick<User, 'username' | 'password'>) =>
        http.post<null>('/users', user),

    // 更新用户信息
    updateUser: (id: number, user: Pick<User, 'username'>) =>
        http.put<null>(`/users/${id}`, user),

    // 删除用户
    deleteUser: (id: number) =>
        http.delete<null>(`/users/${id}`),

    // 重置密码
    resetPassword: (id: number, newPassword: string) =>
        http.put<null>(`/users/${id}/resetPassword`, { newPassword })
}